package com.tan.androidtest.process;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.widget.TextView;

import com.tan.androidtest.IMyAidlInterface;
import com.tan.androidtest.R;
import com.tan.androidtest.base.BaseActivity;
import com.tan.androidtest.service.TestAIDLService;
import com.tan.androidtest.util.ToastUtil;

/**
 * 测试多进程
 */

public class TestMultiProcessActivity extends BaseActivity {


    @Override
    public int initLayoutId() {
        return R.layout.activity_test_multi_process_layout;
    }

    @Override
    public void initTitle(TextView tv_bar_left, TextView tv_bar_title, TextView tv_bar_right) {
        tv_bar_title.setText("测试多进程");
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {
        Intent intent = new Intent(getApplicationContext(), TestAIDLService.class);
        //startService(intent);// 魅族手机要先start 然后bind才有用
        bindService(intent, connection, Context.BIND_AUTO_CREATE);
    }

    ServiceConnection connection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            IMyAidlInterface iMyAidlInterface = IMyAidlInterface.Stub.asInterface(service);
            try {
                String message = iMyAidlInterface.getMessage();
                ToastUtil.showToast(getApplicationContext(), "接收到的: " + message);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };


}
